package com.dd.dus.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dd.dc.entity.users.DCommonCode;
import com.dd.dus.service.impl.DCommonCodeServiceImpl;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 数据字典表 前端控制器
 * </p>
 *
 * @author JueDream
 * @since 2021-03-05
 */
@Slf4j
@RestController
@RequestMapping("/user/d-common-code/")
public class DCommonCodeController {

    @Autowired
    DCommonCodeServiceImpl commonCodeService;

    @ApiOperation(value = "数据字典分页(父级/子级)")
    @PostMapping("/queryCodeList")
    public Page<DCommonCode> queryCodeList(@RequestParam Integer page, @RequestParam Integer limit, @RequestParam String type, @RequestParam String codeName){
        return commonCodeService.queryCodeList(page, limit, type, codeName);
    };

    @ApiOperation(value = "数据字典新增")
    @PostMapping("/insert")
    public Integer insert(@RequestBody DCommonCode commonCode){
        return commonCodeService.insert(commonCode);
    };

    @ApiOperation(value = "数据字典更新")
    @PostMapping("/updateById")
    public boolean updateById(@RequestBody DCommonCode commonCode){
        return commonCodeService.updateById(commonCode);
    };

    @ApiOperation(value = "数据字典批量新增子集")
    @PostMapping("/saveBathChildCode")
    public boolean saveBathChildCode(@RequestBody List<DCommonCode> children){
        return commonCodeService.saveBatch(children);
    };

    @ApiOperation(value = "数据字典根据父集删除子集")
    @PostMapping("/deleteChild")
    public boolean deleteChild(@RequestParam Integer cId){
        return commonCodeService.deleteChild(cId);
    };

    @ApiOperation(value = "数据字典删除")
    @PostMapping("/delete")
    public boolean delete(@RequestParam Integer cId){
        return commonCodeService.removeById(cId);
    };
}
